package com.lostandfound.controller;


import com.lostandfound.pojo.FindAny;
import com.lostandfound.pojo.Recruit;
import com.lostandfound.pojo.Result;
import com.lostandfound.pojo.dto.PublishDto;
import com.lostandfound.service.PublishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
@Slf4j
@RequestMapping("/publish")
public class PublishController {

    @Autowired
    private PublishService publishService;


    /**
     * 发布
     * @param publishDto
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody PublishDto publishDto) {
        /*RecommendStaff recommendStaff = new RecommendStaff();
        BeanUtils.copyProperties(empDto,recommendStaff);
        StaffEmp staffEmp = new StaffEmp();
        BeanUtils.copyProperties(empDto,staffEmp);
        log.info("======================staffEmp:{}",staffEmp);
        empAdminService.add(recommendStaff,empDto);*/
        log.info("publish:{}", publishDto);
        String contacts = publishDto.getCategory();
        if (contacts.equals("寻物启事")){
            publishDto.setStamp(1);
            FindAny findAny = new FindAny();
            BeanUtils.copyProperties(publishDto,findAny);
            log.info("===============publish:{}", publishDto);
            findAny.setReleaseTime(LocalDateTime.now());
            findAny.setLostTime(publishDto.getLocalDate());
            findAny.setLostPlace(publishDto.getLocalPlace());
            publishService.add(findAny);
            return Result.success("添加成功",null);
        }else if (contacts.equals("失物招领")){
            publishDto.setStamp(0);
            Recruit recruit = new Recruit();
            BeanUtils.copyProperties(publishDto,recruit);
            recruit.setReleaseTime(LocalDateTime.now());
            recruit.setCollectTime(publishDto.getLocalDate());
            recruit.setCollectPlace(publishDto.getLocalPlace());
            log.info("===============recruit:{}",recruit);
            publishService.addRecruit(recruit);
            return Result.success("添加成功",null);
        }

        return Result.success("请认真填写发布类别!",null);

    }



}
